package com.whiteape.book.ui.adapter.holder;

import android.view.View;
import android.widget.TextView;

import com.whiteape.book.R;
import com.whiteape.book.model.bo.TypefaceBo;
import com.whiteape.book.ui.base.adapter.ViewHolderImpl;


/**
 * Created by newbiechen on 17-5-16.
 */

public class TypefaceHolder extends ViewHolderImpl<TypefaceBo> {

    private TextView mTvName;
    private TextView mTvState;
    private TextView mTvSize;
    private TextView mTvAction;

    @Override
    public void initView() {
        mTvName = findById(R.id.typeface_tv_name);
        mTvSize = findById(R.id.typeface_tv_size);
        mTvState = findById(R.id.typeface_tv_state);
        mTvAction = findById(R.id.typeface_tv_action);
    }

    @Override
    public void onBind(TypefaceBo value, int pos) {
        mTvName.setText(value.getName());
        mTvSize.setText(value.getSize());
        mTvState.setText(value.getState());
        mTvAction.setText(value.getAction());
        switch (value.getStateType()) {
            case TypefaceBo.STATE_TYPE_UNDOWNLOADED:
                mTvState.setTextColor(getContext().getResources().getColor(R.color.md_deep_orange_300));
                mTvAction.setBackground(getContext().getResources().getDrawable(R.drawable.typeface_action_bg));
                mTvAction.setTextColor(getContext().getResources().getColor(R.color.light_blue));
                break;
            case TypefaceBo.STATE_TYPE_DOWNLOADED:
                mTvState.setTextColor(getContext().getResources().getColor(R.color.md_green_400));
                mTvAction.setBackground(getContext().getResources().getDrawable(R.drawable.typeface_action_bg));
                mTvAction.setTextColor(getContext().getResources().getColor(R.color.light_blue));
                break;
            case TypefaceBo.STATE_TYPE_DOWNLOADING:
                mTvState.setTextColor(getContext().getResources().getColor(R.color.md_deep_orange_300));
                mTvAction.setBackground(getContext().getResources().getDrawable(R.drawable.typeface_action_bg));
                mTvAction.setTextColor(getContext().getResources().getColor(R.color.light_blue));
                break;
            case TypefaceBo.STATE_TYPE_USING:
                mTvState.setTextColor(getContext().getResources().getColor(R.color.md_green_400));
                mTvAction.setBackground(getContext().getResources().getDrawable(R.drawable.typeface_action_disable_bg));
                mTvAction.setTextColor(getContext().getResources().getColor(R.color.md_blue_grey_200));
                break;
        }
        if (value.getStateType() == TypefaceBo.STATE_TYPE_UNDOWNLOADED ||
                value.getStateType() == TypefaceBo.STATE_TYPE_DOWNLOADING) {
            mTvState.setTextColor(getContext().getResources().getColor(R.color.md_deep_orange_300));
        }

    }

    @Override
    protected int getItemLayoutId() {
        return R.layout.item_typeface_manage;
    }

    public View getAction() {
        return mTvAction;
    }
}
